package com.firebird.app.kotlin.stock.trend

import android.app.Application
import com.android.volley.RequestQueue
import com.android.volley.toolbox.HurlStack
import com.android.volley.toolbox.Volley
import com.firebird.app.kotlin.stock.trend.utils.Log
import com.squareup.okhttp.OkHttpClient
import com.squareup.okhttp.OkUrlFactory
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import kotlin.properties.Delegates

/**
 * @author ljk
 * @date   2019年10月5日
 */
class StockApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Log.setLevel(Log.DEBUG) //设置Log打印级别
        //StockGlobalExceptionHandler exceptionHandler = StockGlobalExceptionHandler.getInstance();
//exceptionHandler.init(this);
        //requestQueue = Volley.newRequestQueue(applicationContext)
        instance=this
        requestQueue=initQueue()
    }

    companion object {
        var instance:StockApp by Delegates.notNull()
        //Volley请求队列
        var requestQueue: RequestQueue? = null
    }

    fun initQueue():RequestQueue{
        val factory= OkUrlFactory(OkHttpClient())
        val hurlStack=object :HurlStack(){
            @Throws(IOException::class)
            override fun createConnection(url: URL): HttpURLConnection {
                return factory.open(url)
            }
        }
        return Volley.newRequestQueue(this,hurlStack)
    }
}